/*
ont-space - The ontology-based resource metadata repository
Copyright (c) 2006-2008, Information Eng. Research Unit - Univ. of Alcalá
http://www.cc.uah.es/ie
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License along
with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.ontspace.util.translator.lom2owl.adapter;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Adapts a Careo repository file in order to translate in to OWL. 
 */
public class CareoAdapter {

    /**
     * <p>This method adapts a Careo Repository learningObject in order to 
     * translate it to OWL using the general translation.  
     *  
     */
    public String adaptCareo(String careoFilePath) throws IOException {

        String resultedCareoFilePath =
                careoFilePath.substring(0,
                (careoFilePath.length() - 4)) + "Adapted.xml";
        int pos =
                0;
        try {

            BufferedReader bf =
                    new BufferedReader(new FileReader(careoFilePath));
            BufferedWriter bw =
                    new BufferedWriter(new FileWriter(resultedCareoFilePath));
            String sString;

            while ((sString =
                    bf.readLine()) != null) {

                String requiredTextAL =
                        "aggregationlevel";
                String newStringAL =
                        "aggregationLevel";
                if (sString.indexOf(requiredTextAL) > -1) {
                    pos =
                            sString.indexOf(requiredTextAL);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringAL + sString.substring((pos + 16),
                            sString.length()));
                }
                String requiredTextTAR =
                        "<typicalagerange />";
                String newStringTAR =
                        "<typicalAgeRange />";
                if (sString.indexOf(requiredTextTAR) > -1) {
                    pos =
                            sString.indexOf(requiredTextTAR);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringTAR + sString.substring((pos + 19),
                            sString.length()));
                }
                String requiredTextOPR =
                        "<otherplatformrequirements />";
                String newStringOPR =
                        "<otherPlatformRequirements />";
                if (sString.indexOf(requiredTextOPR) > -1) {
                    pos =
                            sString.indexOf(requiredTextOPR);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringOPR + sString.substring((pos + 29),
                            sString.length()));
                }

                String requiredTextIR =
                        "<installationremarks />";
                String newStringIR =
                        "<installationRemarks />";
                if (sString.indexOf(requiredTextIR) > -1) {
                    pos =
                            sString.indexOf(requiredTextIR);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringIR + sString.substring((pos + 23),
                            sString.length()));
                }

                String requiredTextMS =
                        "metadataschema";
                String newStringMS =
                        "metadataSchema";
                while (sString.indexOf(requiredTextMS) > -1) {
                    pos =
                            sString.indexOf(requiredTextMS);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringMS + sString.substring((pos + 14),
                            sString.length()));

                }
                String requiredTextmV =
                        "minimumversion";
                String newStringmV =
                        "minimumVersion";
                while (sString.indexOf(requiredTextmV) > -1) {
                    pos =
                            sString.indexOf(requiredTextmV);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringmV + sString.substring((pos + 14),
                            sString.length()));
                }
                String requiredTextMV =
                        "maximumversion";
                String newStringMV =
                        "maximumVersion";
                while (sString.indexOf(requiredTextMV) > -1) {
                    pos =
                            sString.indexOf(requiredTextMV);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringMV + sString.substring((pos + 14),
                            sString.length()));
                }

                String requiredTextIT =
                        "interactivitytype";
                String newStringIT =
                        "interactivityType";
                while (sString.indexOf(requiredTextIT) > -1) {
                    pos =
                            sString.indexOf(requiredTextIT);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringIT + sString.substring((pos + 17),
                            sString.length()));
                }
                String requiredTextLRT =
                        "learningresourcetype";
                String newStringLRT =
                        "learningResourceType";
                while (sString.indexOf(requiredTextLRT) > -1) {
                    pos =
                            sString.indexOf(requiredTextLRT);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringLRT + sString.substring((pos + 20),
                            sString.length()));
                }
                String requiredTextIL =
                        "interactivitylevel";
                String newStringIL =
                        "interactivityLevel";
                while (sString.indexOf(requiredTextIL) > -1) {
                    pos =
                            sString.indexOf(requiredTextIL);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringIL + sString.substring((pos + 18),
                            sString.length()));
                }

                String requiredTextSD =
                        "semanticdensity";
                String newStringSD =
                        "semanticDensity";
                while (sString.indexOf(requiredTextSD) > -1) {
                    pos =
                            sString.indexOf(requiredTextSD);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringSD + sString.substring((pos + 15),
                            sString.length()));
                }

                String requiredTextIEUR =
                        "intendeduserrole";
                String newStringIEUR =
                        "intendedEndUserRole";
                while (sString.indexOf(requiredTextIEUR) > -1) {
                    pos =
                            sString.indexOf(requiredTextIEUR);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringIEUR + sString.substring((pos + 16),
                            sString.length()));

                }

                String requiredTextTLT =
                        "typicallearningtime";
                String newStringTLT =
                        "typicalLearningTime";
                while (sString.indexOf(requiredTextTLT) > -1) {
                    pos =
                            sString.indexOf(requiredTextTLT);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringTLT + sString.substring((pos + 19),
                            sString.length()));

                }

                String requiredTextCAOR =
                        "copyrightandotherrestrictions";
                String newStringCAOR =
                        "copyrightAndOtherRestrictions";
                while (sString.indexOf(requiredTextCAOR) > -1) {
                    pos =
                            sString.indexOf(requiredTextCAOR);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringCAOR + sString.substring((pos + 29),
                            sString.length()));

                }

                String requiredTextTP =
                        "taxonpath";
                String newStringTP =
                        "taxonPath";
                while (sString.indexOf(requiredTextTP) > -1) {
                    pos =
                            sString.indexOf(requiredTextTP);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringTP + sString.substring((pos + 9),
                            sString.length()));

                }

                String requiredTextLCC =
                        "lifecycle";
                String newStringLCC =
                        "lifeCycle";
                while (sString.indexOf(requiredTextLCC) > -1) {
                    pos =
                            sString.indexOf(requiredTextLCC);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringLCC + sString.substring((pos + 9),
                            sString.length()));

                }
                String requiredTextCE =
                        "centity";
                String newStringCE =
                        "entity";
                while (sString.indexOf(requiredTextCE) > -1) {
                    pos =
                            sString.indexOf(requiredTextCE);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringCE + sString.substring((pos + 7),
                            sString.length()));

                }

                String requiredTextLS =
                        "</langstring>";
                String newStringLS =
                        "";
                while (sString.indexOf(requiredTextLS) > -1) {
                    pos =
                            sString.indexOf(requiredTextLS);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringLS + sString.substring((pos + 13),
                            sString.length()));

                }

                String requiredTextLSB =
                        "<langstring>";
                String newStringLSB =
                        "";
                while (sString.indexOf(requiredTextLSB) > -1) {
                    pos =
                            sString.indexOf(requiredTextLSB);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringLSB + sString.substring((pos + 12),
                            sString.length()));

                }

                String requiredTextXSD =
                        "http://linux2.commons.ucalgary.ca/rob_text/ims1_2_1";
                String newStringXSD =
                        "http://ltsc.ieee.org/xsd/LOM";
                while (sString.indexOf(requiredTextXSD) > -1) {
                    pos =
                            sString.indexOf(requiredTextXSD);
                    sString =
                            "" + (sString.substring(0, pos) +
                            newStringXSD + sString.substring((pos + 51),
                            sString.length()));
                }

                String requiredText23 =
                        "<title>";
                String newString23 =
                        "<title><string language ='en'>";
                String sC =
                        sString;
                int counter =
                        0;

                while (sC.indexOf(requiredText23) > -1) {
                    sC =
                            sC.substring(sC.indexOf(requiredText23) +
                            requiredText23.length(), sC.length());
                    counter++;
                }
                int i =
                        0;

                String sC1 =
                        sString;
                String sC2 =
                        "";

                while ((sC1.indexOf(requiredText23) > -1) && (i <= counter)) {
                    pos =
                            sC1.indexOf(requiredText23);
                    sC1 =
                            "" + (sC1.substring(0, pos) + newString23 +
                            sC1.substring((pos + 7), sC1.length()));

                    sC2 =
                            sC2 + (sC1.substring(0, pos) + newString23);
                    sC1 =
                            sC1.substring((pos + 30), sC1.length());

                    i++;

                }
                sC2 =
                        sC2 + sC1.substring(0, sC1.length());
                sString =
                        sC2;

                String requiredText24 =
                        "</title>";
                String newString24 =
                        "</string></title>";
                String sC24 =
                        sString;
                int counter24 =
                        0;

                while (sC24.indexOf(requiredText24) > -1) {
                    sC24 =
                            sC24.substring(sC24.indexOf(requiredText24) +
                            requiredText24.length(), sC24.length());
                    counter24++;
                }
                int i24 =
                        0;

                String sC124 =
                        sString;
                String sC224 =
                        "";

                while ((sC124.indexOf(requiredText24) > -1) &&
                        (i24 <= counter24)) {
                    pos =
                            sC124.indexOf(requiredText24);
                    sC124 =
                            "" + (sC124.substring(0, pos) + newString24 +
                            sC124.substring((pos + 8), sC124.length()));

                    sC224 =
                            sC224 + (sC124.substring(0, pos) +
                            newString24);
                    sC124 =
                            sC124.substring((pos + 17), sC124.length());

                    i24++;

                }
                sC224 =
                        sC224 + sC124.substring(0, sC124.length());
                sString =
                        sC224;

                String requiredText25 =
                        "<requirement>";
                String newString25 =
                        "<requirement><orComposite>";
                String sC25 =
                        sString;
                int counter25 =
                        0;

                while (sC25.indexOf(requiredText25) > -1) {
                    sC25 =
                            sC25.substring(sC25.indexOf(requiredText25) +
                            requiredText25.length(), sC25.length());
                    counter25++;
                }
                int i25 =
                        0;

                String sC125 =
                        sString;
                String sC225 =
                        "";

                while ((sC125.indexOf(requiredText25) > -1) &&
                        (i25 <= counter25)) {
                    pos =
                            sC125.indexOf(requiredText25);
                    sC125 =
                            "" + (sC125.substring(0, pos) + newString25 +
                            sC125.substring((pos + 13), sC125.length()));

                    sC225 =
                            sC225 + (sC125.substring(0, pos) +
                            newString25);
                    sC125 =
                            sC125.substring((pos + 26), sC125.length());

                    i25++;

                }
                sC225 =
                        sC225 + sC125.substring(0, sC125.length());
                sString =
                        sC225;

                String requiredText26 =
                        "</requirement>";
                String newString26 =
                        "</orComposite></requirement>";
                String sC26 =
                        sString;
                int counter26 =
                        0;

                while (sC26.indexOf(requiredText26) > -1) {
                    sC26 =
                            sC26.substring(sC26.indexOf(requiredText26) +
                            requiredText26.length(), sC26.length());
                    counter26++;
                }
                int i26 =
                        0;

                String sC126 =
                        sString;
                String sC226 =
                        "";

                while ((sC126.indexOf(requiredText26) > -1) &&
                        (i26 <= counter26)) {
                    pos =
                            sC126.indexOf(requiredText26);
                    sC126 =
                            "" + (sC126.substring(0, pos) + newString26 +
                            sC126.substring((pos + 14), sC126.length()));

                    sC226 =
                            sC226 + (sC126.substring(0, pos) +
                            newString26);
                    sC126 =
                            sC126.substring((pos + 28), sC126.length());

                    i26++;

                }
                sC226 =
                        sC226 + sC126.substring(0, sC126.length());
                sString =
                        sC226;

                String requiredText27 =
                        "<keyword>";
                String newString27 =
                        "<keyword><string language ='en'>";
                String sC27 =
                        sString;
                int counter27 =
                        0;

                while (sC27.indexOf(requiredText27) > -1) {
                    sC27 =
                            sC27.substring(sC27.indexOf(requiredText27) +
                            requiredText27.length(), sC27.length());
                    counter27++;
                }
                int i27 =
                        0;

                String sC127 =
                        sString;
                String sC227 =
                        "";

                while ((sC127.indexOf(requiredText27) > -1) &&
                        (i27 <= counter27)) {
                    pos =
                            sC127.indexOf(requiredText27);
                    sC127 =
                            "" + (sC127.substring(0, pos) + newString27 +
                            sC127.substring((pos + 9), sC127.length()));

                    sC227 =
                            sC227 + (sC127.substring(0, pos) +
                            newString27);
                    sC127 =
                            sC127.substring((pos + 32), sC127.length());

                    i27++;

                }
                sC227 =
                        sC227 + sC127.substring(0, sC127.length());
                sString =
                        sC227;

                String requiredText28 =
                        "</keyword>";
                String newString28 =
                        "</string></keyword>";
                String sC28 =
                        sString;
                int counter28 =
                        0;

                while (sC28.indexOf(requiredText28) > -1) {
                    sC28 =
                            sC28.substring(sC28.indexOf(requiredText28) +
                            requiredText28.length(), sC28.length());
                    counter28++;
                }
                int i28 =
                        0;

                String sC128 =
                        sString;
                String sC228 =
                        "";

                while ((sC128.indexOf(requiredText28) > -1) &&
                        (i28 <= counter28)) {
                    pos =
                            sC128.indexOf(requiredText28);
                    sC128 =
                            "" + (sC128.substring(0, pos) + newString28 +
                            sC128.substring((pos + 10), sC128.length()));

                    sC228 =
                            sC228 + (sC128.substring(0, pos) +
                            newString28);
                    sC128 =
                            sC128.substring((pos + 19), sC128.length());

                    i28++;

                }
                sC228 =
                        sC228 + sC128.substring(0, sC128.length());
                sString =
                        sC228;

                String requiredText29 =
                        "<description>";
                String newString29 =
                        "<description><string language ='en'>";
                String sC29 =
                        sString;
                int counter29 =
                        0;

                while (sC29.indexOf(requiredText29) > -1) {
                    sC29 =
                            sC29.substring(sC29.indexOf(requiredText29) +
                            requiredText29.length(), sC29.length());
                    counter29++;
                }
                int i29 =
                        0;

                String sC129 =
                        sString;
                String sC229 =
                        "";

                while ((sC129.indexOf(requiredText29) > -1) &&
                        (i29 <= counter29)) {
                    pos =
                            sC129.indexOf(requiredText29);
                    sC129 =
                            "" + (sC129.substring(0, pos) + newString29 +
                            sC129.substring((pos + 13), sC129.length()));

                    sC229 =
                            sC229 + (sC129.substring(0, pos) +
                            newString29);
                    sC129 =
                            sC129.substring((pos + 36), sC129.length());

                    i29++;

                }
                sC229 =
                        sC229 + sC129.substring(0, sC129.length());
                sString =
                        sC229;

                String requiredText30 =
                        "</description>";
                String newString30 =
                        "</string></description>";
                String sC30 =
                        sString;
                int counter30 =
                        0;

                while (sC30.indexOf(requiredText30) > -1) {
                    sC30 =
                            sC30.substring(sC30.indexOf(requiredText30) +
                            requiredText30.length(), sC30.length());
                    counter30++;
                }
                int i30 =
                        0;

                String sC130 =
                        sString;
                String sC230 =
                        "";

                while ((sC130.indexOf(requiredText30) > -1) &&
                        (i30 <= counter30)) {
                    pos =
                            sC130.indexOf(requiredText30);
                    sC130 =
                            "" + (sC130.substring(0, pos) + newString30 +
                            sC130.substring((pos + 14), sC130.length()));

                    sC230 =
                            sC230 + (sC130.substring(0, pos) +
                            newString30);
                    sC130 =
                            sC130.substring((pos + 23), sC130.length());

                    i30++;

                }
                sC230 =
                        sC230 + sC130.substring(0, sC130.length());
                sString =
                        sC230;

                String requiredText31 =
                        "<version>";
                String newString31 =
                        "<version><string language ='en'>";
                String sC31 =
                        sString;
                int counter31 =
                        0;

                while (sC31.indexOf(requiredText31) > -1) {
                    sC31 =
                            sC31.substring(sC31.indexOf(requiredText31) +
                            requiredText31.length(), sC31.length());
                    counter31++;
                }
                int i31 =
                        0;

                String sC131 =
                        sString;
                String sC231 =
                        "";

                while ((sC131.indexOf(requiredText31) > -1) &&
                        (i31 <= counter31)) {
                    pos =
                            sC131.indexOf(requiredText31);
                    sC131 =
                            "" + (sC131.substring(0, pos) + newString31 +
                            sC131.substring((pos + 9), sC131.length()));

                    sC231 =
                            sC231 + (sC131.substring(0, pos) +
                            newString31);
                    sC131 =
                            sC131.substring((pos + 32), sC131.length());

                    i31++;

                }
                sC231 =
                        sC231 + sC131.substring(0, sC131.length());
                sString =
                        sC231;

                String requiredText32 =
                        "</version>";
                String newString32 =
                        "</string></version>";
                String sC32 =
                        sString;
                int counter32 =
                        0;

                while (sC32.indexOf(requiredText32) > -1) {
                    sC32 =
                            sC32.substring(sC32.indexOf(requiredText32) +
                            requiredText32.length(), sC32.length());
                    counter32++;
                }
                int i32 =
                        0;

                String sC132 =
                        sString;
                String sC232 =
                        "";

                while ((sC132.indexOf(requiredText32) > -1) &&
                        (i32 <= counter32)) {
                    pos =
                            sC132.indexOf(requiredText32);
                    sC132 =
                            "" + (sC132.substring(0, pos) + newString32 +
                            sC132.substring((pos + 10), sC132.length()));

                    sC232 =
                            sC232 + (sC132.substring(0, pos) +
                            newString32);
                    sC132 =
                            sC132.substring((pos + 19), sC132.length());

                    i32++;

                }
                sC232 =
                        sC232 + sC132.substring(0, sC132.length());
                sString =
                        sC232;

                String requiredText33 =
                        "<installationremarks>";
                String newString33 =
                        "<installationRemarks><string language ='en'>";
                String sC33 =
                        sString;
                int counter33 =
                        0;

                while (sC33.indexOf(requiredText33) > -1) {
                    sC33 =
                            sC33.substring(sC33.indexOf(requiredText33) +
                            requiredText33.length(), sC33.length());
                    counter33++;
                }
                int i33 =
                        0;

                String sC133 =
                        sString;
                String sC233 =
                        "";

                while ((sC133.indexOf(requiredText33) > -1) &&
                        (i33 <= counter33)) {
                    pos =
                            sC133.indexOf(requiredText33);
                    sC133 =
                            "" + (sC133.substring(0, pos) + newString33 +
                            sC133.substring((pos + 21), sC133.length()));

                    sC233 =
                            sC233 + (sC133.substring(0, pos) +
                            newString33);
                    sC133 =
                            sC133.substring((pos + 44), sC133.length());

                    i33++;

                }
                sC233 =
                        sC233 + sC133.substring(0, sC133.length());
                sString =
                        sC233;

                String requiredText34 =
                        "</installationremarks>";
                String newString34 =
                        "</string></installationRemarks>";
                String sC34 =
                        sString;
                int counter34 =
                        0;

                while (sC34.indexOf(requiredText34) > -1) {
                    sC34 =
                            sC34.substring(sC34.indexOf(requiredText34) +
                            requiredText34.length(), sC34.length());
                    counter34++;
                }
                int i34 =
                        0;

                String sC134 =
                        sString;
                String sC234 =
                        "";

                while ((sC134.indexOf(requiredText34) > -1) &&
                        (i34 <= counter34)) {
                    pos =
                            sC134.indexOf(requiredText34);
                    sC134 =
                            "" + (sC134.substring(0, pos) + newString34 +
                            sC134.substring((pos + 22), sC134.length()));

                    sC234 =
                            sC234 + (sC134.substring(0, pos) +
                            newString34);
                    sC134 =
                            sC134.substring((pos + 31), sC134.length());

                    i34++;

                }
                sC234 =
                        sC234 + sC134.substring(0, sC134.length());
                sString =
                        sC234;

                String requiredText35 =
                        "<otherplatformrequirements>";
                String newString35 =
                        "<otherPlatformRequirements><string language ='en'>";
                String sC35 =
                        sString;
                int counter35 =
                        0;

                while (sC35.indexOf(requiredText35) > -1) {
                    sC35 =
                            sC35.substring(sC35.indexOf(requiredText35) +
                            requiredText35.length(), sC35.length());
                    counter35++;
                }
                int i35 =
                        0;

                String sC135 =
                        sString;
                String sC235 =
                        "";

                while ((sC135.indexOf(requiredText35) > -1) &&
                        (i35 <= counter35)) {
                    pos =
                            sC135.indexOf(requiredText35);
                    sC135 =
                            "" + (sC135.substring(0, pos) + newString35 +
                            sC135.substring((pos + 27), sC135.length()));

                    sC235 =
                            sC235 + (sC135.substring(0, pos) +
                            newString35);
                    sC135 =
                            sC135.substring((pos + 50), sC135.length());

                    i35++;

                }
                sC235 =
                        sC235 + sC135.substring(0, sC135.length());
                sString =
                        sC235;

                String requiredText36 =
                        "</otherplatformrequirements>";
                String newString36 =
                        "</string></otherPlatformRequirements>";
                String sC36 =
                        sString;
                int counter36 =
                        0;

                while (sC36.indexOf(requiredText36) > -1) {
                    sC36 =
                            sC36.substring(sC36.indexOf(requiredText36) +
                            requiredText36.length(), sC36.length());
                    counter36++;
                }
                int i36 =
                        0;

                String sC136 =
                        sString;
                String sC236 =
                        "";

                while ((sC136.indexOf(requiredText36) > -1) &&
                        (i36 <= counter36)) {
                    pos =
                            sC136.indexOf(requiredText36);
                    sC136 =
                            "" + (sC136.substring(0, pos) + newString36 +
                            sC136.substring((pos + 28), sC136.length()));

                    sC236 =
                            sC236 + (sC136.substring(0, pos) +
                            newString36);
                    sC136 =
                            sC136.substring((pos + 37), sC136.length());

                    i36++;

                }
                sC236 =
                        sC236 + sC136.substring(0, sC136.length());
                sString =
                        sC236;

                String requiredText37 =
                        "<typicalagerange>";
                String newString37 =
                        "<typicalAgeRange><string language ='en'>";
                String sC37 =
                        sString;
                int counter37 =
                        0;

                while (sC37.indexOf(requiredText37) > -1) {
                    sC37 =
                            sC37.substring(sC37.indexOf(requiredText37) +
                            requiredText37.length(), sC37.length());
                    counter37++;
                }
                int i37 =
                        0;

                String sC137 =
                        sString;
                String sC237 =
                        "";

                while ((sC137.indexOf(requiredText37) > -1) &&
                        (i37 <= counter37)) {
                    pos =
                            sC137.indexOf(requiredText37);
                    sC137 =
                            "" + (sC137.substring(0, pos) + newString37 +
                            sC137.substring((pos + 17), sC137.length()));

                    sC237 =
                            sC237 + (sC137.substring(0, pos) +
                            newString37);
                    sC137 =
                            sC137.substring((pos + 40), sC137.length());

                    i37++;

                }
                sC237 =
                        sC237 + sC137.substring(0, sC137.length());
                sString =
                        sC237;

                String requiredText40 =
                        "</typicalagerange>";
                String newString40 =
                        "</string></typicalAgeRange>";
                String sC40 =
                        sString;
                int counter40 =
                        0;

                while (sC40.indexOf(requiredText40) > -1) {
                    sC40 =
                            sC40.substring(sC40.indexOf(requiredText40) +
                            requiredText40.length(), sC40.length());
                    counter40++;
                }
                int i40 =
                        0;

                String sC140 =
                        sString;
                String sC240 =
                        "";

                while ((sC140.indexOf(requiredText40) > -1) &&
                        (i40 <= counter40)) {
                    pos =
                            sC140.indexOf(requiredText40);
                    sC140 =
                            "" + (sC140.substring(0, pos) + newString40 +
                            sC140.substring((pos + 18), sC140.length()));

                    sC240 =
                            sC240 + (sC140.substring(0, pos) +
                            newString40);
                    sC140 =
                            sC140.substring((pos + 27), sC140.length());

                    i40++;

                }
                sC240 =
                        sC240 + sC140.substring(0, sC140.length());
                sString =
                        sC240;

                String requiredText41 =
                        "<catalogentry>";
                String newString41 =
                        "<identifier><catalog>";
                String sC41 =
                        sString;
                int counter41 =
                        0;

                while (sC41.indexOf(requiredText41) > -1) {
                    sC41 =
                            sC41.substring(sC41.indexOf(requiredText41) +
                            requiredText41.length(), sC41.length());
                    counter41++;
                }
                int i41 =
                        0;

                String sC141 =
                        sString;
                String sC241 =
                        "";

                while ((sC141.indexOf(requiredText41) > -1) &&
                        (i41 <= counter41)) {
                    pos =
                            sC141.indexOf(requiredText41);
                    sC141 =
                            "" + (sC141.substring(0, pos) + newString41 +
                            sC141.substring((pos + 14), sC141.length()));

                    sC241 =
                            sC241 + (sC141.substring(0, pos) +
                            newString41);
                    sC141 =
                            sC141.substring((pos + 21), sC141.length());

                    i41++;

                }
                sC241 =
                        sC241 + sC141.substring(0, sC141.length());
                sString =
                        sC241;

                String requiredText42 =
                        "</catalogentry>";
                String newString42 =
                        "</catalog></identifier>";
                String sC42 =
                        sString;
                int counter42 =
                        0;

                while (sC42.indexOf(requiredText42) > -1) {
                    sC42 =
                            sC42.substring(sC42.indexOf(requiredText42) +
                            requiredText42.length(), sC42.length());
                    counter42++;
                }
                int i42 =
                        0;

                String sC142 =
                        sString;
                String sC242 =
                        "";

                while ((sC142.indexOf(requiredText42) > -1) &&
                        (i42 <= counter42)) {
                    pos =
                            sC142.indexOf(requiredText42);
                    sC142 =
                            "" + (sC142.substring(0, pos) + newString42 +
                            sC142.substring((pos + 15), sC142.length()));

                    sC242 =
                            sC242 + (sC142.substring(0, pos) +
                            newString42);
                    sC142 =
                            sC142.substring((pos + 23), sC142.length());

                    i42++;

                }
                sC242 =
                        sC242 + sC142.substring(0, sC142.length());
                sString =
                        sC242;

                bw.write(sString);

            }
            bw.close();

        } catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }

        return resultedCareoFilePath;
    }
}


